var app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    selected:true,
    selected1:false,
    selected2: false,
    selected3: false,
    selected4: false,
    types:'all',
    info:[],
    goods_id:'',
    curpage:1,
    request_num:0, //加载结束
    is_show_time: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var goods_id = options.goods_id
   
    var types = that.data.types
    wx.request({
      url: app.configData.shop.api_url + '/index.php?ctl=Goods_Goods&met=getGoodsEvaluationList&typ=json',
      method: 'GET',
      data: { sou: 'wap', goods_id: goods_id, type: types, curpage: that.data.curpage,page:10},
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        that.setData({
          info: res.data.data.items,
          goods_id:goods_id,
          is_show_time: 0
        })
      
      }
    })
  },
//切换
  prod:function(e){
    var that = this;
    
    var types = e.currentTarget.dataset.click
    switch (types) {
      case 'all':
        that.setData({
          selected: true,
          selected1: false,
          selected2: false,
          selected3: false,
          selected4: false,
        })
        break;
      case '1':
        that.setData({
          selected: false,
          selected1: true,
          selected2: false,
          selected3: false,
          selected4: false,

        })
        break;
      case '2':
        that.setData({
          selected: false,
          selected1: false,
          selected2: true,
          selected3: false,
          selected4: false,
        })
        break;
      case '3':
        that.setData({
          selected: false,
          selected1: false,
          selected2: false,
          selected3: true,
          selected4: false,
        })
        break;
      case '4':
        that.setData({
          selected: false,
          selected1: false,
          selected2: false,
          selected3: false,
          selected4: true,
        })
        break;
    }

    var that = this
    var goods_id = that.data.goods_id
   

    wx.request({
      url: app.configData.shop.api_url + '/index.php?ctl=Goods_Goods&met=getGoodsEvaluationList&typ=json',
      method: 'GET',
      data: { sou: 'wap', goods_id: goods_id, type: types, curpage: 1, page: 10 },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        
        that.setData({
          info: res.data.data.items,
          goods_id: goods_id,
          request_num: 0,
          curpage:1
        })

      }
    })
  },

  /**
    * 页面上拉触底事件的处理函数
    */
  onReachBottom: function () {
    var that = this
    var curpage = that.data.curpage
    var types = that.data.types
    if (that.data.request_num == 1 ){
      return false
    }
    curpage++
    wx.request({
      url: app.configData.shop.api_url + '/index.php?ctl=Goods_Goods&met=getGoodsEvaluationList&typ=json',
      method: 'GET',
      data: { sou: 'wap', goods_id: that.data.goods_id, type: types, curpage: curpage, page: 10 },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.data.data.items.length > 0){
          var product_list = that.data.info
          for (var z in res.data.data.items) {
            product_list.push(res.data.data.items[z])
          }
          
          that.setData({
            info: product_list,
            curpage: curpage
          })
        }else{
          that.setData({
            request_num: 1
          })
        }
      }
    })
  },
  //图片点击事件
  imgYu: function (event) {
    var src = event.currentTarget.dataset.src;//获取data-src
    var imgList = event.currentTarget.dataset.list;//获取data-list
    //图片预览
    wx.previewImage({
      current: src, // 当前显示图片的http链接
      urls: imgList // 需要预览的图片http链接列表
    })
  }
})